<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 450px;
            margin: 100px auto;
        }

        input {
            width: 350px;
            height: 47px;
            outline: none;
        }

        button {
            width: 90px;
            height: 50px;
        }

        .bottom {
            width: 353px;
        }

        .bottom ul li {
            list-style: none;
            height: 50px;
            line-height: 50px;
            border-bottom: 1px solid #666;
            border-left: 1px solid #666;
            border-right: 1px solid #666;
            padding-left: 5px;
        }

        .bottom ul li:hover {
            background-color: #999;
        }
    </style>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
</head>

<body>
<div class="box">
    <div class="top">
        <input type="text" name="keyname" class="keyname" placeholder="请输入商品信息" class="keyname">
        <button>搜索</button>
    </div>
    <div class="bottom">
        <ul class="keyul"></ul>
    </div>
</div>


<script>
    $(".keyname").blur(function(){
        if (!$(".keyname").val()){
            $('.keyul').empty();
        }else{
            $.ajax({
                type:"post",
                url:"/keywords",
                data:{
                    "keyname":$(".keyname").val()
                },
                success:function(data){
                    $('.keyul').empty();
                    $.each(data,function(index,item){
                        let $li=$("<li>"+item+"</li>")
                        $li.click(function(){
                            $(".keyname").val($(this).html())
                            $('.keyul').empty();
                        })
                        $(".keyul").append($li)
                    })
                }
            })
        }
    })
</script>
</body>

</html>